//
//  main.c
//  循环链表的设计与实现
//
//  Created by ZJ on 2018/7/13.
//  Copyright © 2018年 iCatch Technology Inc. All rights reserved.
//

#include <stdio.h>
#include <stdlib.h>
#include "circlelist.h"

typedef struct Value {
    CircleListNode circlenode;
    int v;
} Value;

int main(int argc, const char * argv[]) {
    // insert code here...
    
    CircleList *list = CircleList_Create();
    
    Value v1, v2, v3, v4, v5, v6, v7, v8;
    
    v1.v = 1;
    v2.v = 2;
    v3.v = 3;
    v4.v = 4;
    v5.v = 5;
    v6.v = 6;
    v7.v = 7;
    v8.v = 8;

    CircleList_Insert(list, (CircleListNode *)&v1, 0);
    CircleList_Insert(list, (CircleListNode *)&v2, 0);
    CircleList_Insert(list, (CircleListNode *)&v3, 0);
    CircleList_Insert(list, (CircleListNode *)&v4, 0);

    // 怎样证明一个链表是循环链表（打印两次如果能重复则为循环链表）
    for (int i = 0; i < CircleList_Length(list) * 2; i++) {
        Value *pv = (Value *)Circle_Get(list, i);
        
        printf("%d\n", pv->v);
    }
    
//    Value *ret = (Value *)CircleList_DeleteNode(list, (CircleListNode *)&v1);
//    printf("删除的元素为：%d\n", ret->v);
    
    Value *ret = (Value *)Circle_Delete(list, 3);
    printf("删除的元素为：%d\n", ret->v);
    
    for (int i = 0; i < CircleList_Length(list); i++) {
        Value *pv = (Value *)Circle_Get(list, i);
        
        printf("%d\n", pv->v);
    }
    
    ret = (Value *)CircleList_Current(list);
    printf("游标当前节点： %d\n", ret->v);
    
    /*
    Value *ret = (Value *)CircleList_Current(list);
    printf("游标当前节点： %d\n", ret->v);
    
    ret = (Value *)CircleList_Next(list);
    printf("游标next节点： %d\n", ret->v);
    */
    
    /*
    Value *ret = (Value *)CircleList_DeleteNode(list, (CircleListNode *)&v4);
    printf("删除的元素为：%d\n", ret->v);
    
    for (int i = 0; i < CircleList_Length(list) * 2; i++) {
        Value *pv = (Value *)Circle_Get(list, i);
        
        printf("%d\n", pv->v);
    }
    
    ret = (Value *)CircleList_DeleteNode(list, (CircleListNode *)&v1);
    printf("删除的元素为：%d\n", ret->v);
    
    for (int i = 0; i < CircleList_Length(list) * 2; i++) {
        Value *pv = (Value *)Circle_Get(list, i);
        
        printf("%d\n", pv->v);
    }
    */
    
    /*
    while (CircleList_Length(list) > 0) {
        Circle_Delete(list, 0);
    }
    */
    
    CircleList_Destroy(list);
    
    printf("Hello, World!\n");
    return 0;
}
